const mime = require('mime')

const { validate } = require('schema-utils')

const schema = {
  type: 'object',
  properties: {
    limit: {
      type: 'number'
    },
    outputPath: {
      type: 'string'
    }
  }
}
function loader(source){
  const options = this.getOptions();
  validate(schema, source, 'url-loader')

  if(options.limit >= source.length){
    return `module.exports = "data:${mime.getType(this.resourcePath)};base64,${source.toString('base64')}"`
  }else{
   return require('./file-loader').call(this,source)
  }
}
loader.raw = true

module.exports = loader